provider "alicloud" {
  region                = local.region
  version               = "1.199"
}

terraform {
  required_version      = "~> 0.12"  
  backend "oss" {
    bucket              = "deeproute-terraform-resources"
    key                 = "stag/services/cloudbox-redis-example"
    tablestore_endpoint = "https://terraform-status.cn-shenzhen.ots.aliyuncs.com"
    tablestore_table    = "terraform_statelock_table"    
    region              = "cn-shenzhen"
  }
}

locals {
  region                = "cn-shenzhen"
  env                   = "stg"
  name                  = "cloudbox-redis-example"
  billing               = "team-cloud"
  team                  = "cloud"
}

locals {
  cloudbox_vpc                    = "vpc-wz94gvzjd0qnjti24e8is"
  public_cloudbox_vswitch         = "vsw-wz9itft4zwi2waedturj6"
  stg_cloudbox_vswitch            = "vsw-wz93tv3xo2ljpg4qppg4e"
  availability_zone               = "cn-shenzhen-cnszsg-cb"
}

module "sg" {
  source                = "git@code.deeproute.ai:deeproute-org/cloud/cloud/k8s-deployment/ops-terraform.git//alicloud/sg?ref=module.v1.0.4"
  sg_name               = local.fullname
  vpc_id                = var.vpc
  inbound_rules         = {
    "0" = ["0.0.0.0/0", "22/22", "tcp"]
  }
}

module "redis" {
  source                  = "git@code.deeproute.ai:deeproute-org/cloud/cloud/k8s-deployment/ops-terraform.git//alicloud/redis?ref=module.v1.0.4"
  zone_id                 = local.availability_zone
  instance_name           = local.fullname
  instance_type           = "Redis"
  engine_version          = "5.0"
  instance_class          = "redis.basic.small.default" #redis.amber.logic.sharding.1g.2db.0rodb.6proxy.multithread"  //ref: https://help.aliyun.com/document_detail/26350.html?spm=a2c4g.11186623.6.580.4d2d754eqDUHep
  vswitch_id              = local.stg_cloudbox_vswitch
  security_group_id       = module.sg.sg_id
  security_ips            = []
  kms_encrypted_password  = "MDBkM2FjZTItNjExMC00ZDVhLWJiNjktMTZkNTBhYzkxNTlkyFiHfnjx8scdUApP/qqNn2UbGVqn9i7nr7Kz6ayXN1OFtyKiFb5WJdtvepwZaAwlvyh/"
  # password                = "NzFlYjA3OTMtYTk0Zi00YmZj"
  tags = {
    Name                  = local.name
    Environment           = local.env
    Billing               = local.billing
    Team                  = local.team
  }
}